home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6981 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: crchh327.rich.bnr.ca!jobell
  2. From: jobell@bnr.ca (Bret Bieghler)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is there a standard for * and & placement style?
  5. Date: 20 Feb 1996 13:20:59 GMT
  6. Organization: Bell-Northern Research Ltd.
  7. Message-ID: <4gchrr$7r9@crchh327.rich.bnr.ca>
  8. References: <3128BD31.4AF8@wildfire.com>
  9. NNTP-Posting-Host: crchh524.rich.bnr.ca
  10.  
  11. In article <3128BD31.4AF8@wildfire.com>,
  12. Stonewall Ballard  <stoney@wildfire.com> wrote:
  13. >I'm trying to find out whether there is a "standard" for the 
  14. >placement of * and &. A survey of C++ texts shows that most use
  15. >
  16. >Form 1
  17. >  int&  foo;
  18. >  int*  foo;
  19. >
  20. >while some use
  21. >
  22. >Form 2
  23. >  int&  foo;
  24. >  int  *foo;
  25. >
  26. >and nobody uses (although I've seen this a lot in code)
  27. >
  28. >Form 3
  29. >  int  &foo;
  30. >  int  *foo;
  31.  
  32. Most C textbooks that I've seen use the following:
  33.  
  34.     int *foo;
  35.  
  36. and give the reason that it reminds you that the pointer
  37. operator only associates itself with one variable, thus
  38.  
  39.     int *foo, foo2, foo3
  40.  
  41. declares an int pointer (foo), and two ints.
  42.  
  43. Thus,
  44.  
  45.     int* foo, foo2, foo3;
  46.  
  47. is equivalent.
  48.  
  49. However, since it is "bad practice" to delcare more
  50. than one variable on a line, most C++ books use
  51.  
  52.     int* foo
  53.  
  54. to show you that you are declaring an int pointer.
  55.  
  56. or
  57.  
  58.     int& foo
  59.  
  60. int reference.
  61.  
  62. JB
  63.  
  64. >Thanks very much!
  65. >
  66. >  - Stoney
  67.  
  68. your welcome.
  69. >
  70. >
  71. >----------------------------------------------------------------
  72. >-------
  73. >Stonewall Ballard       "I have one grunch but the eggplant over 
  74. >there"
  75. >stoney@wildfire.com (work)                Wildfire 
  76. >Communications, Inc.
  77. >stoney@beeblebrox.com (home)          
  78. >http://www.tiac.net/users/stoney/
  79.  
  80.  
  81. -- 
  82. Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
  83. Northern Telecom / Bell-Northern Research
  84. "What?  Evacuate now, in our moment of triumph?  Surely you overestimate their chances."
  85.